// 引入 request 文件
import request from './index.js'

// 手机一键登录，获取token
export const phoneLogin = (params) => {
	console.log();
	return request({
		url: '/phoneLogin',
		method: 'post',
		data: params,
		header: {} // 自定义
	})
}

// 用户注册接口
export const apiLogin = (params) => {
	return request({
		url: '/login',
		method: 'post',
		data: params
	})
}

// 注册页热门标签选择列表
export const getHotTopics = (params) => {
	return request({
		url: '/client/topics/getHotTopics',
		method: 'get',
		data: params
	})
}

// 用户注册接口
export const register = (params) => {
	return request({
		url: '/system/user/userInfoSupplement',
		method: 'post',
		data: params
	})
}

// 获取用户主页接口
export const getUser = (params) => {
	let url;
	if (params) url = '/system/user/userInfo?userId=' + params
	else url = '/system/user/userInfo'
	return request({
		url: url,
		method: 'get',
	})
}

// 获取用户主页相册 /client/post/getOwnPostImages   时光轴  图片   参数是  userId
export const getOwnPostImages = (params) => {
	return request({
		url: '/client/post/getOwnPostImages',
		method: 'post',
		data: params
	})
}

// 获取相册列表
export const getAlbumList = (params) => {
	return request({
		url: '/clientFileList/fileList/list',
		method: 'get',
		data: params
	})
}

// 首页头部视频和轮播图
export const somentList = (params) => {
	return request({
		url: '/soment/soment/list',
		method: 'get',
		data: params
	})
}


// 新增相册
export const addAlbum = (params) => {
	return request({
		url: '/clientFileList/fileList',
		method: 'post',
		data: params
	})
}

// 删除相册
export const deleteImage = (params) => {
	return request({
		url: '/clientFileList/fileList/deleteImage',
		method: 'get',
		data: params
	})
}
// 用户个人主页资料更新
export const getUserInfoUpdate = (params) => {
	return request({
		url: '/clientUser/clientUser/userInfoUpdate',
		method: 'post',
		data: params
	})
}
// 设置好友备注
export const setFriendRemark = (params) => {
	return request({
		url: `/follow/clientFollow/setFriendRemark?friendId=${params.friendId}&remark=${params.remark}`, // 确保路径与后端一致
		method: 'post'
	});
}
// 根据id查询用户信息
export const getClient = (id) => {
	return request({
		url: `/client/user/getClient/${id}`,
		method: 'get'
	})
}

// 获取城市信息
export const getCityList = (params) => {
	return request({
		url: '/cityName/region/list',
		method: 'get',
		data: params
	})
}

// 生成电子相册
export const addClientImages = (params) => {
	return request({
		url: '/client/post/addClientImages',
		method: 'post',
		data: params
	})
}

// 获取城市信息
export const getRegionByHistoy = (params) => {
	return request({
		url: '/cityName/region/getRegionByHistoy',
		method: 'get',
		data: params
	})
}

// 城市模糊查询
export const getCityListBlurSearch = (params) => {
	return request({
		url: '/cityName/region/list',
		method: 'get',
		data: params
	})
}

// 选取某个城市调用新增历史记录
export const addRegionUserHistoy = (params) => {
	return request({
		url: '/cityName/region/addRegionUserHistoy',
		method: 'post',
		data: params
	})
}

// 根据手机号查询归属地
export const phoneLocation = (params) => {
	return request({
		url: '/client/post/phoneLocation',
		method: 'get',
		data: params
	})
}

// 个人信息认证提交
export const getPerson = (params) => {
	return request({
		url: '/person/person',
		method: 'post',
		data: params
	})
}

// 申请本地人
export const updateUserByUserId = (params) => {
	return request({
		url: '/person/person/updateUserByUserId',
		method: 'get',
		data: params
	})
}

// 申请达人
export const expertAddOrEdit = (params) => {
	return request({
		url: '/expert/expert/expertAddOrEdit',
		method: 'post',
		data: params
	})
}

// 达人详情页
export const getExpert = (id) => {
	return request({
		url: `/expert/expert/${id}`,
		method: 'get',
	})
}
// 根据本地人身份选择的城市获取用户是否满足
export const getClientPostHigh = (params) => {
	return request({
		url: '/expert/expert/getClientPostHigh',
		method: 'get',
		data: params
	})
}

// 查询本地身份认证信息
export const getPersonByUserId = (params) => {
	return request({
		url: '/person/person/getPersonByUserId',
		method: 'get',
		data: params
	})
}

// 获取已认证本地身份的城市
export const selectPersonByUserId = (params) => {
	return request({
		url: '/person/person/selectPersonByUserId',
		method: 'get',
		data: params
	})
}
// 任务中心接口
export const getTaskList = (params) => {
	return request({
		url: '/task/task/getTaskList',
		method: 'get',
		data: params
	})
}

// 任务中心--签到
export const sign = (params) => {
	return request({
		url: '/sign/sign',
		method: 'post',
		data: params
	})
}

// 根据用户id获取本地向导审核信息
export const getGuide = (id) => {
	return request({
		url: `/guide/guide/${id}`,
		method: 'get',
	})
}
// 申请本地向导下一步
export const postGuide = (params) => {
	return request({
		url: '/guide/guide',
		method: 'post',
		data: params
	})
}
// 向导列表
export const guideList = (params) => {
	return request({
		url: '/guide/guide/list',
		method: 'get',
		data:params
	})
}
// 获取服务描述模版
export const clientServiceList = (params) => {
	return request({
		url: '/clientService/clientService/list',
		method: 'get',
		data: params
	})
}

// 预约地陪新增单价人数
export const serviceType = (params) => {
	return request({
		url: '/serviceType/serviceType',
		method: 'post',
		data: params
	})
}

// 预约地陪新增单价人数
export const serviceTypeList = (params) => {
	return request({
		url: '/serviceType/serviceType/list',
		method: 'get',
		data: params
	})
}
// 服务下架
export const updateServiceTypesByUserId = (params) => {
	return request({
		url: '/serviceType/serviceType/updateServiceTypesByUserId',
		method: 'get',
		data: params
	})
}

// 获取向导已接单日期，处理日历不可选
export const getOrdersDateTimeById = (params) => {
	return request({
		url: '/orders/orders/getOrdersDateTimeById',
		method: 'get',
		data: params
	})
}
// 创建订单
export const orders = (params) => {
	return request({
		url: '/orders/orders',
		method: 'post',
		data: params
	})
}

// 订单列表
export const ordersList = (params) => {
	return request({
		url: '/orders/orders/list',
		method: 'get',
		data: params
	})
}

// 订单详情
export const getOrderDetail = (id) => {
	return request({
		url: `/orders/orders/${id}`,
		method: 'get',
	})
}

// 退改规则
export const getDeductionConfigList = (params) => {
	return request({
		url: '/deduction/deductionConfig/list',
		method: 'get',
		data: params
	})
}

// 订单改价（向导）
export const updateMoney = (params) => {
	return request({
		url: '/orders/orders/updateMoney',
		method: 'post',
		data: params
	})
}

// 订单删除
export const deleteOrders = (params) => {
	return request({
		url: '/orders/orders/deleteOrders',
		method: 'get',
		data: params
	})
}

// 取消订单
export const updateOrdersStatus = (params) => {
	return request({
		url: '/orders/orders/updateOrdersStatus',
		method: 'get',
		data: params
	})
}

// 订单评价
export const guideComment = (params) => {
	return request({
		url: '/guideComment/guideComment',
		method: 'post',
		data: params
	})
}

// 获取视频列表
export const getVideos = (params) => {
	return request({
		url: '/client/post/getVideos',
		method: 'get',
		data: params
	})
}

/**
 * @param {Number} userId - 用户的ID
 * @param {Number} queryType - 帖子类型
 * @param {Number} pageNo - 当前页数
 * @param {Number} pageSize - 一页多少
 **/
// 查询帖子信息
export const getPosts = (params) => {
	return request({
		url: '/client/post/getPosts',
		method: 'get',
		data: params
	})
}

export const getHomePagePosts = (params) => {
	return request({
		url: '/client/post/getHomePagePosts',
		method: 'get',
		data: params
	})
}

// 查询时光轴信息
export const getOwnPosts = (params) => {
	return request({
		url: '/client/post/getOwnPosts',
		method: 'post',
		data: params
	})
}

// 关注接口
export const postFollow = (params) => {
	return request({
		url: '/follow/clientFollow/click',
		method: 'get',
		data: params
	})
}

/**
 * @param {file} filedata - 图片地址
 **/
// 上传文件
export const addFile = (params) => {
	return request({
		url: '/client/post/addFile',
		method: 'post',
		data: params
	})
}

/**
 * @param {String} id - id
 **/
// 文件撤销
export const revokeFile = (params) => {
	return request({
		url: '/client/post/fileRollback',
		method: 'get',
		data: params
	})
}

/**
 * @param {Number}  - 图片地址
 **/
// 发布帖子
export const publishPost = (params) => {
	return request({
		url: '/client/post/addPost',
		method: 'post',
		data: params
	})
}

// 获取话题库话题列表
export const getTopicsList = (params) => {
	return request({
		url: '/client/topics/list',
		method: 'get',
		data: params
	})
}

// 用户通讯录列表
export const getFriendsList = (params) => {
	return request({
		url: '/follow/clientFollow/friendsList',
		method: 'get'
	})
}

// 用户关注接口
export const getClientFollow = (params) => {
	return request({
		url: '/follow/clientFollow/click',
		method: 'get',
		data: params
	})
}

// 首页-本地达人列表
export const getExpertList = (params) => {
	return request({
		url: '/expert/expert/list',
		method: 'get',
		data: params
	})
}

// 获取帖子详情
export const getPostDetails = (postId) => {
	return request({
		url: `/client/post/getPostDetails?postId=${postId}`,
		method: 'get'
	})
}

// 本地圈子话题榜单
export const topicsList = (params) => {
	return request({
		url: '/clientTopicsList/topicsList/list',
		method: 'get',
		data: params
	})
}

// 巷子美食头条
export const activityList = (params) => {
	return request({
		url: '/activity/activity/list',
		method: 'get',
		data: params
	})
}
// 本地向导 推荐
export const getByUserList = (params) => {
	return request({
		url: '/clientUser/clientUser/getByUserList',
		method: 'post',
		data: params
	})
}

// 本地向导的 关注
export const getClientUserByUserId = (params) => {
	return request({
		url: '/clientUser/clientUser/getClientUserByUserId',
		method: 'get',
		data: params
	})
}
// 时光轴帖子点赞列表查询
export const getClientLike = (params) => {
	return request({
		url: `/clientLike/clientLike/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&postId=${params.postId}`,
		method: 'get'
	})
}

// 帖子浏览记录
export const getCommentCount = (params) => {
	return request({
		url: '/client/post/getCommentCount',
		method: 'get',
		data: params
	})
}
// 获取评论列表
export const getCommentList = (postId) => {
	return request({
		url: `/clientComment/comment/list?postId=${postId}`,
		method: 'get'
	})
}

// 获取评论下的回复
export const getCommentChildrenList = (postId) => {
	return request({
		url: `/clientComment/comment/commentChildrenList?commentId=${postId}`,
		method: 'get'
	})
}

// 新增评论
export const addComment = (params) => {
	return request({
		url: '/clientComment/comment/add',
		method: 'post',
		data: params
	})
}
// 评论删除
export const removeComment = (params) => {
	return request({
		url: '/clientComment/comment/remove',
		method: 'post',
		data: params
	})
}
// 点赞评论
export const addCommentLike = (commentId) => {
	return request({
		url: `/clientComment/commentLike/add?commentId=${commentId}`,
		method: 'post'
	})
}

// 评论取消点赞
export const cancelCommentLike = (commentId) => {
	return request({
		url: `/clientComment/commentLike/cancelLike?commentId=${commentId}`,
		method: 'post'
	})
}

// 帖子点赞
export const postClientLike = (params) => {
	return request({
		url: `/clientLike/clientLike/add?postId=${params.postId}&userId=${params.userId}`,
		method: 'post'
	})
}
// 帖子取消点赞
export const postCancelLike = (params) => {
	return request({
		url: `/clientLike/clientLike/cancelLike?postId=${params.postId}&userId=${params.userId}`,
		method: 'post'
	})
}
// 帖子收藏
export const postClientCollect = (postId) => {
	return request({
		url: `/clientCollect/collect/add?postId=${postId}`,
		method: 'post'
	})
}
// 帖子取消收藏
export const postCancelCollect = (postId) => {
	return request({
		url: `/clientCollect/collect/cancelCollect?postId=${postId}`,
		method: 'post'
	})
}

// 帖子踩一踩
export const clientStep = (params) => {
	return request({
		url: `/clientStep/clientStep`,
		method: 'post',
		data: params
	})
}

// 帖子取消踩一踩
export const deleteClientStep = (params) => {
	return request({
		url: `/clientStep/clientStep/deleteClientStep`,
		method: 'post',
		data: params
	})
}

// 土著玩乐轮播图
export const getSoment = () => {
	return request({
		url: `/soment/soment/2`,
		method: 'get'
	})
}

// 时光轴统计数据
export const getOwnPostsInfoCount = (postId) => {
	return request({
		url: `/client/post/getOwnPostsInfoCount`,
		method: 'get'
	})
}
// 删除帖子
export const deletePost = (postId) => {
	return request({
		url: `/client/post/deletePost?postId=${postId}`,
		method: 'get'
	})
}

// 访客记录查询接口
export const getVisitorRecord = (params) => {
	return request({
		url: `/clientVisitor/visitorRecord/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`,
		method: 'get'
	})
}

// 用户关注关系列表
export const getClientFollowList = (queryType) => {
	return request({
		url: `/follow/clientFollow/list?queryType=${queryType}`,
		method: 'get'
	})
}

// 标签新增接口
export const postAddTopics = (params) => {
	return request({
		url: `/client/topics/add`,
		method: 'post',
		data: params
	})
}
// 标签选择/新增接口
export const postChooseTopic = (params) => {
	return request({
		url: `/client/topics/chooseTopic`,
		method: 'post',
		data: params
	})
}

// 打赏记录列表（帖子详情查询）
export const getPayHoneyUser = (params) => {
	return request({
		url: '/honey/honey/getPayHoneyUser',
		method: 'post',
		data: params
	})
}
// 获取七牛云上传凭证 (前端准备阶段用模拟函数替代真实调用)
export const getQiniuToken = (params) => {
	// 真实情况下会调用 request({...})
	// 在后端未完成前，我们会在 Vue 组件中直接调用模拟函数
	return request({
		url: `/qnyUpload/getUploadToken?originalFilename=${params.originalFilename}&purpose=${params.purpose}`, // 你的后端凭证接口路径
		method: 'get',
		data: params
	});
	// console.warn("使用的是 getQiniuToken 的桩函数定义，请在后端完成后替换为真实API调用。");
	// return Promise.reject(new Error("后端 /api/qiniu/upload-token 接口尚未实现"));
};

// 更新帖子
export const updatePost = (params) => {
	return request({
		url: `/client/post/updatePost`, // 假设的更新接口路径
		method: 'post', // 或者 'put'，根据后端定义
		data: params
	});
};

// 用户头像修改
export const updateUserAvatar = (params) => {
	return request({
		url: `/clientUser/clientUser/updateUserAvatar`, // 假设的更新接口路径
		method: 'post', // 或者 'put'，根据后端定义
		data: params
	});
};

// 用户背景图修改
export const updateUserBackground = (params) => {
	return request({
		url: `/clientUser/clientUser/updateUserBackground`, // 假设的更新接口路径
		method: 'post', // 或者 'put'，根据后端定义
		data: params
	});
};

// 获取文件服务器CDN域名
export const getQiNiuUrl = (friendId) => {
	return request({
		url: `/qnyUpload/getDomain`,
		method: 'get'
	})
}

// 本地达人认证  查询是否满足提交条件
export const getExpertStarts = (params) => {
	return request({
		url: `/expert/expert/getExpertStarts`,
		method: 'get',
		data: params
	})
}

// 蜂蜜数量查询
export const getHoneySum = (params) => {
	return request({
		url: `/honey/honey/getHoneySum`,
		method: 'get',
		data: params
	})
}

// 打赏确认
export const getHoneySumTip = (params) => {
	return request({
		url: `/honey/honey/getHoneySumTip`,
		method: 'post',
		data: params
	})
}

// 获取充值列表

export const honeyPayList = (params) => {
	return request({
		url: `/honeyPay/honeyPay/list`,
		method: 'get',
		data: params
	})
}
// 蜂蜜充值
export const payClientUserHoney = (params) => {
	return request({
		url: `/honey/honey/payClientUserHoney`,
		method: 'get',
		data: params
	})
}

// 蜂蜜记录
export const Honeylist = (params) => {
	return request({
		url: `/honey/honey/list`,
		method: 'get',
		data: params
	})
}

export const HoneylistByHoney = (params) => {
	return request({
		url: `/honey/honey/listByHoney`,
		method: 'get',
		data: params
	})
}

// 评论列表
export const guideCommentList = (params) => {
	return request({
		url: `/guideComment/guideComment/list`,
		method: 'get',
		data: params
	})
}
// 评论列表关联类型的数量查询
export const getListNumber = (params) => {
	return request({
		url: `/guideComment/guideComment/getListNumber`,
		method: 'get',
		data: params
	})
}

/**
 * 搜索用户列表
 * @param {object} params - 查询参数
 * @param {string} [params.keyword] - 通用搜索关键词 (后端可能需要这样的参数)
 * @param {string} [params.nickName] - 按昵称搜索
 * @param {string} [params.userName] - 按用户名搜索
 * @param {number} params.pageNum - 页码
 * @param {number} params.pageSize - 每页数量
 */
export const getClientUserList = (params) => {
	return request({
		url: '/clientUser/clientUser/list', // 请替换为实际的后端API路径
		method: 'post',
		data: params
	});
};

/************************************************************ IM即时通信 ************************************************************/
/*
	* IM即时通信
	* POST https://{host}/{org_name}/{app_name}/users

*/
// IM-APPToken获取

export const getIMAPPToken = (params) => {
	return request({
		url: `/im/appToken`, // 假设的更新接口路径
		method: 'get', // 或者 'put'，根据后端定义
	});
};
// export const postIMAPPToken = (params) => {
// 	return new Promise((resolve, reject) => {
// 		uni.request({
// 			url: 'https://a1.easecdn.com/1164250524193037/demo/token',
// 			method: 'post',
// 			data: params,
// 			success: (res) => {
// 				let data = {
// 					code:res.statusCode,
// 					data:res.data
// 				} 
// 				resolve(data); 
// 			},
// 			fail: (err) => {
// 				reject(err);
// 			}
// 		});
// 	})
// };
// IM用户注册
export const postIMUserRegister = (params) => {
	return new Promise((resolve, reject) => {
		uni.request({
			// 1164250524193037为orgName demo为appName
			// 1133251021209359#demo
			url: 'https://a1.easemob.com/1133251021209359/demo/users',
			method: 'post',
			data: params,
			success: (res) => {
				let data = {
					code: res.statusCode,
					data: res.data
				}
				resolve(data);
			},
			fail: (err) => {
				reject(err);
			}
		});
	})
};

// IM用户Token
export const getIMUserToken = (params) => {
	let header = {
		'Content-Type': 'application/json', // 自定义，跟后台约定好传什么格式的
		'Authorization': uni.getStorageSync('im_app_token'),
	};
	return new Promise((resolve, reject) => {
		uni.request({
			// url: 'https://a1.easecdn.com/1164250524193037/demo/token',
			url: 'https://a1.easemob.com/1133251021209359/demo/token',
			method: 'post',
			data: params,
			header: header,
			success: (res) => {
				let data = {
					code: res.statusCode,
					data: res.data
				}
				resolve(data);
			},
			fail: (err) => {
				reject(err);
			}
		});
	})
};



// 消息本地存储接口
export const postMessageReport = (params) => {
	return request({
		url: `/chat/message/report`,
		method: 'post',
		data: params
	});
};

// 消息发送接口
export const postMessageSend = (params) => {
	return request({
		url: `/chat/message/send`,
		method: 'post',
		data: params
	});
};

// 总未读消息数
export const getTotalUnreadCount = () => {
	return request({
		url: `/chat/conversation/totalUnreadCount`,
		method: 'get'
	})
}

// 会话列表接口
export const getConversationList = () => {
	return request({
		url: `/chat/conversation/list`,
		method: 'get'
	})
}
// 进入聊天会话
export const getPrivateRead = (friendId) => {
	return request({
		url: `/chat/conversation/private/${friendId}/read`,
		method: 'post'
	})
}
// 离开聊天会话
export const postConversationLeave = () => {
	return request({
		url: `/chat/conversation/leaveCurrentChat`,
		method: 'post'
	});
};
// 历史消息记录
export const getMessagesList = (params) => {
	return request({
		url: `/chat/message/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&userIdForQuery=${params.userIdForQuery}&targetIdForQuery=${params.targetIdForQuery}&isGroup=${params.isGroup}`,
		method: 'get'
	})
}

/************************************************************ 声网 ************************************************************/
// 获取声网RTC Token
export const getAgoraToken = (params) => {
	// ！！警告：这仅用于开发阶段，生产环境必须由后端动态生成Token ！！

	// --- 在这里粘贴您从声网控制台生成的临时Token ---
	const tempToken =
		'007eJxTYDjNNXP+ZaPTrnu+++zaNJPl8UarMPU2j9x34hIfPV/OC9+gwJBmbJiYZJSUlpJsYWmSapmUZGZulGhqlpSWZGFgaJFqzLTdP6MhkJGBXV6KlZEBAkF8AYaS1OKS+OSMxLy81Jz4qspKBgYAOE4kWQ=='; // <--- 替换成你的临时Token

	console.warn("声网提示：正在使用前端生成的临时Token，仅限开发测试！");
	console.log("请求的频道名参数:", params.channelName); // 打印出来，确保和生成Token时用的频道名一致

	// 使用 Promise.resolve 来模拟一个成功的异步请求
	return Promise.resolve({
		// 模拟后端返回的数据结构
		data: {
			code: 200, // 模拟成功状态码
			msg: 'success',
			data: {
				token: tempToken
			}
		}
	});

	/*
	// 真实的后端请求代码 (保留注释，备用)
	return request({
		url: '/agora/rtc/token', // 你的后端接口路径
		method: 'post', // 或 'get'
		data: params,
	});
	*/
}


/************************************************************ AI问问 ************************************************************/
// 模拟获取AI热门推荐
export const getAiHotTopics = () => {
	return Promise.resolve({
		data: {
			data: [
				'突然爆火的哀牢山', '6.14淮安南京苏超联赛', '西沙海底墓',
				'跟着中国地理游山西', '北京环球影城', '阿勒泰旅游因电视剧出让'
			]
		}
	});
};

// 模拟获取AI建议问题
export const getAiSuggestions = () => {
	const allSuggestions = [
		['介绍一下淮安的历史和文化', '淮安的最佳旅游时间？', '淮安有哪些值得去拍照打卡的地方？', '近期淮安有什么特别的活动？'],
		['推荐一下北京的特色美食', '故宫的游览路线怎么规划？', '长城哪个段更适合初次游客？', '北京有哪些小众胡同值得一逛？'],
		['上海迪士尼的省钱攻略', '外滩夜景最佳观赏点在哪？', '上海博物馆需要预约吗？', '推荐几个上海的文艺书店。'],
	];
	const randomIndex = Math.floor(Math.random() * allSuggestions.length);
	return Promise.resolve({
		data: {
			data: allSuggestions[randomIndex]
		}
	});
};
// 获取AI回复信息
export const postAIAsk = (params) => {
	return request({
		url: '/deepseek/AIAsk',
		method: 'post',
		data: params
	});
}

/**
 * 获取AI问答历史记录
 * @param {object} params - { pageNum, pageSize }
 */
export const getAiChatHistory = (params) => {
	return request({
		// 假设后端的历史记录接口路径是这个
		url: `/ai/chat/history`,
		method: 'get',
		data: params
	});
};

/**
 * 发送消息给AI并获取回复
 * @param {object} params - { content, type: 'text' | 'image' }
 */
export const sendAiMessage = (params) => {
	return request({
		// 这里我们复用并重命名之前的 postAIAsk 接口
		url: '/deepseek/AIAsk',
		method: 'post',
		data: params
	});
};;

/**
 * 获取巷子美食页面的列表数据
 * @param {object} params - { pageNum, pageSize }
 */
export const getCuisineList = (params) => {
	return request({
		// 假设后端的历史记录接口路径是这个
		url: `/alley/cuisine/list`,
		method: 'get',
		data: params
	});
};